package com.d0330;

import java.io.*;
import java.net.Socket;

public class TCPClient {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("127.0.0.1",4700);
            BufferedReader sin =new BufferedReader(new InputStreamReader(System.in));
            String line = sin. readLine();

            DataOutputStream os = new DataOutputStream(socket.getOutputStream());//接收
            DataInputStream is = new DataInputStream(socket.getInputStream());//输入

            while (!line.equals("exit")){
                os.writeUTF(line);//向客户端写入数据
                os.flush();//把缓存内容提交
                System.out.println("Server:"+is.readUTF());
                line = sin.readLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
